/*
*    Phantom v2.0 GUI Automation Software
*    Copyright (C) 2009  John C. Van Arsdall (john@phantomtest.com)
*
*    This program is free software; you can redistribute it and/or modify
*    it under the terms of the GNU General Public License as published by
*    the Free Software Foundation; either version 2 of the License, or
*    (at your option) any later version.
*
*    This program is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*    GNU General Public License for more details.
*
*    You should have received a copy of the GNU General Public License along
*    with this program; if not, write to the Free Software Foundation, Inc.,
*    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
#include "ssi_singleinput.h"

CSingleInput::CSingleInput(void)
{
}

CSingleInput::~CSingleInput(void)
{
}

SSI_BOOL CSingleInput::SetInput(const String& Line, const String& Name)
{
  SetInputName(Name);
	//SetFileName(Name);
  CScriptLine sLine;
  sLine.Line = Line;
  sLine.LineNum = 1;
  PushLine(sLine);
  return 1;
}

SSI_BOOL CSingleInput::GetNextLine(CScriptLine &Ret)
{
  if(!CurrLine) return 0;
  if(CurrLine->next()){
    CurrLine = CurrLine->next();
    CurrLine->Get(Ret);
    return 1;
  }
  return 0;
}

SSI_INT64 CSingleInput::Query(const CScriptStatement& aStatement)
{
  return 1;
}

SSI_BOOL CSingleInput::Run(CEngine* Eng)
{
  CurrLine = SSI_NULL;
  CScriptLine aLine;
	ScriptNode* sNode = 0;
  CurrLine = GetTopLine();
  if(!CurrLine) return 0;

  CInterpreter Interp(this);
  Interp.SetEngine(Eng);
  Interp.SetOutDisplay(Eng->GetOutStream());
  
  while(CurrLine)
  {
    CurrLine->Get(aLine);
    if(!Interp.Interpret(aLine.Line, CurrLine)){
      return 0;
    }
  	if(Interp.GetReturnState() || Interp.GetStopState()){
      break;
		}
    if(!CurrLine){
      return 0;
    }
    CurrLine = CurrLine->next();
  }
  return 1;
}





